//
//  PersonalInfoView.m
//  项目三
//
//  Created by rimi1 on 2016/12/13.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "PersonalInfoView.h"

static NSInteger spacing_ = 20;

@implementation PersonalInfoView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.headImage];
        [self addSubview:self.boygView];
        [self.boygView addSubview:self.boy];
        [self.boygView addSubview:self.girl];
    }
    return self;
}

- (UIButton *)buttonWithRect:(CGRect)rect title:(NSString *)title {
    UIButton *button = [[UIButton alloc] initWithFrame:rect];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    return button;
}

#pragma mark - respondsTo...

- (void)respondsToButton:(UIButton *)sender {
    if (self.tapButton) {
        self.tapButton(sender);
    }
}

- (void)respondsToHead {
    if (self.tapHead) {
        self.tapHead();
    }
}

#pragma mark - get

- (UIImageView *)headImage {
    
    if (!_headImage) {
        
        CGFloat diameter = WXQAdaptionHeight(100);
        _headImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, WXQAdaptionHeight(spacing_), diameter, diameter)];
        CGPoint point = _headImage.center;
        point.x = kWIDTH/2;
        _headImage.center = point;
        _headImage.layer.cornerRadius = diameter/2;
        _headImage.layer.masksToBounds = YES;
        _headImage.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(respondsToHead)];
        [_headImage addGestureRecognizer:tap];
        
    }
    return _headImage;
}

- (UIView *)boygView {
    
    if (!_boygView) {
        
        CGFloat width = WXQAdaptionWidth(160);
        CGFloat height = WXQAdaptionHeight(45);
        _boygView = [[UIView alloc] initWithFrame:CGRectMake((kWIDTH - width)/2, CGRectGetMaxY(self.headImage.frame) + WXQAdaptionHeight(spacing_), width, height)];
        _boygView.layer.cornerRadius = WXQAdaptionWidth(5);
        _boygView.layer.masksToBounds = YES;
        
    }
    return _boygView;
}

- (UIButton *)boy {
    
    if (!_boy) {
        
        CGFloat width = WXQAdaptionWidth(80);
        _boy = [self buttonWithRect:CGRectMake(0, 0, width, CGRectGetHeight(self.boygView.bounds)) title:@"男"];
        _boy.selected = YES;
        _boy.tag = 100;
        [_boy addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _boy;
}

- (UIButton *)girl {
    
    if (!_girl) {
        
        CGFloat width = CGRectGetWidth(self.boy.bounds);
        _girl = [self buttonWithRect:CGRectMake(width, CGRectGetMinY(self.boy.frame), width, CGRectGetHeight(self.boy.bounds)) title:@"女"];
        _girl.tag = 101;
        [_girl addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _girl;
}

@end











